package com.stephen.demo.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.BoolType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Entity;
import javax.persistence.Lob;

/*
 *  @Erupt注解修饰在类上，@EruptField注解修饰在字段上
 *  其他注解均为Jpa注解
 */
@Getter
@Setter
@Erupt(
        name = "逻辑删除",
        filter = @Filter("deleted = false")
) // 注意修改sql中的表名
@SQLDelete(sql = "update teacher set deleted = true where id = ?")
@Entity
public class Teacher extends BaseModel {

    @EruptField(
            views = @View(title = "老师姓名"),
            edit = @Edit(title = "老师姓名", notNull = true, search = @Search(vague = true))
    )
    private String name;

    @EruptField(
            views = @View(title = "老师年龄"),
            edit = @Edit(title = "老师年龄", notNull = true)
    )
    private String studentAge;

    @Lob
    @EruptField(
            views = @View(title = "老师性别"),
            edit = @Edit(title = "老师性别", notNull = true, boolType = @BoolType(trueText = "男", falseText = "女"), search = @Search)
    )
    private Boolean studentSex;

    private Boolean deleted = false;

}
